package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.AttractionsBuilding;
import com.huilai.platform.country_platform.model.AttractionsWaterscape;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/2/18
 * 注释：
 */
@Repository
public interface AttractionsWaterscapeReposity extends JpaRepository<AttractionsWaterscape, Integer>, JpaSpecificationExecutor<AttractionsWaterscape> {
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into attractions_waterscape(name, address, `describe`, image)" +
            "values(:#{#attractionsWaterscape.name},:#{#attractionsWaterscape.address},:#{#attractionsWaterscape.describe},:#{#attractionsWaterscape.image})", nativeQuery = true)
    Integer addWaterscape(AttractionsWaterscape attractionsWaterscape);


    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update attractions_waterscape aw set aw.name = :#{#attractionsWaterscape.name}, " +
            "aw.address = :#{#attractionsWaterscape.address}, " +
            "aw.describe = :#{#attractionsWaterscape.describe}, " +
            "aw.image = :#{#attractionsWaterscape.image} where aw.waterscape_id = :#{#attractionsWaterscape.id}",nativeQuery = true)
    Integer updateWaterscape(AttractionsWaterscape attractionsWaterscape);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete from AttractionsWaterscape aw where aw.id = :id")
    Integer deleteWaterscapeById(Integer id);
}